package com.secsbrain.cloudconsole.web.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.secsbrain.cloudconsole.biz.constant.RoleCodeConstants;
import com.secsbrain.cloudconsole.remote.SsoRemoteService;
import com.secsbrain.common.ResponseResult;
import com.secsbrain.frame.sequence.zk.ZkDistributedIdGenerater;
import com.secsbrain.sso.model.dto.system.UserDetailDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/common")
public class CommonController {
    
    private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
    
    @Autowired
    private SsoRemoteService userServiceFacade;
    
    @Autowired
	private ZkDistributedIdGenerater distributedIdGenerater;
    
    /**
     * @apiVersion 1.0.0
     * @api {GET} /common/getOps 获取所有运维人员
     * 
     * @apiGroup Common
     * 
     * @apiSuccess {String[]} data         数据列表
     * @apiSuccess {Number}   data.id   	      用户ID
     * @apiSuccess {Number}   data.realName   用户姓名
     * 
     */
    @RequestMapping(value = "/getOps", method = RequestMethod.GET)
	public ResponseResult<List<UserDetailDTO>> getOps(){
		return userServiceFacade.getUserDTOByRoleCode(RoleCodeConstants.OPS);
	}
    
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    public ResponseResult<?> uploadFile(@RequestParam(value="file") MultipartFile file, HttpServletRequest request) throws IOException{
		return new ResponseResult<>();
	}
    
    @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
    public void downloadFile(String path, HttpServletResponse response) throws IOException{
    	logger.debug("下载文件开始。。。");
    	
    	String group=path.substring(0,path.indexOf("/"));
    	String path1=path.substring(path.indexOf("/")+1,path.length());


    }
    
    
    @RequestMapping(value = "/test", method = RequestMethod.GET)
  	public ResponseResult<?> test(){
		String sque=distributedIdGenerater.generateId("test1");
		return new ResponseResult<>(sque);
    }

}
